package com.cpi.cornpp.customerpurchase.service;

import java.util.List;

import com.cpi.cornpp.common.exception.CornPPException;
import com.cpi.cornpp.customerpurchase.converter.CustomerPurchaseConverter;
import com.cpi.cornpp.customerpurchase.dao.CustomerPurchaseDAO;
import com.cpi.cornpp.futurepurchase.exception.FuturePurchaseException;

public class CustomerPurchaseService {
	
	public List getCustomerPurchasesByFuturePurchase(int futurePurchaseId)throws FuturePurchaseException{
		CustomerPurchaseDAO cupDAO = null;
		List customerPurchasesDTO = null;
		List customerPurchasesView = null;
		try{
			cupDAO = new CustomerPurchaseDAO();
			customerPurchasesDTO = cupDAO.getCustomerPurchasesByFuturePuruchaseId(futurePurchaseId);
			customerPurchasesView = CustomerPurchaseConverter.convertDTOs(customerPurchasesDTO);
		}catch (FuturePurchaseException futurePurchaseException){
			throw futurePurchaseException;
		}catch(Exception exception){
			FuturePurchaseException futurePurchaseException=null;
			exception.printStackTrace(System.out);
			futurePurchaseException= new FuturePurchaseException(exception , CornPPException.LAYER_SERVICE,CornPPException.ACTION_SELECT);
			throw futurePurchaseException;
		}
		return customerPurchasesView;
	}
	
	public List getCustomerPurchasesByDistribution(int cornFutureDistributionId)throws FuturePurchaseException{
		List customerPurchasesViews = null;
		List customerPurchasesDTOs = null;
		CustomerPurchaseDAO customerPurchaseDAO = null;
		try{
			customerPurchaseDAO = new CustomerPurchaseDAO();
			customerPurchasesDTOs = customerPurchaseDAO.getCustomerPurchasesByCornFutureDistrubutionId(cornFutureDistributionId);
			customerPurchasesViews = CustomerPurchaseConverter.convertDTOs(customerPurchasesDTOs);
		}catch (FuturePurchaseException futurePurchaseException){
			throw futurePurchaseException;
		}catch(Exception exception){
			FuturePurchaseException futurePurchaseException=null;
			exception.printStackTrace(System.out);
			futurePurchaseException= new FuturePurchaseException(exception , CornPPException.LAYER_SERVICE,CornPPException.ACTION_SELECT);
			throw futurePurchaseException;
		}
		return customerPurchasesViews;
	}
}